<?php
// 首页显示信息以及基本配置
namespace Partner\Controller;
use Think\Controller;
class IndexController extends CommonController{
   function index(){
        $uid=session('u_id');
        $id=session('id');
        $userinfo=M('partner')->find($id);
        $user_info=M('users')->find($uid);
        $this->assign('user_info',$user_info);
        $this->assign('userinfo',$userinfo);
        $this->assign('title','首页');

       $this->display();
    }
    function index_info(){
        $id=session('id');
        $user_info=M('partner')->find($id);
        $bids=explode(',',$user_info['b_id']);

        if($user_info['level']==1){
            $user_where['province']=$bids[0];
        }
        if($user_info['level']==2){
            $user_where['province']=$bids[0];
            $user_where['city']=$bids[1];
        }
        if($user_info['level']==3){
            $user_where['province']=$bids[0];
            $user_where['city']=$bids[1];
            $user_where['district']=$bids[2];

        }
        if($user_info['level']==1){
            $where['province_id']=$bids[0];
        }
        if($user_info['level']==2){
            $where['province_id']=$bids[0];
            $where['city_id']=$bids[1];
        }
        if($user_info['level']==3){
            $where['province_id']=$bids[0];
            $where['city_id']=$bids[1];
            $where['district_id']=$bids[2];

        }
        $users   =   D('Users');
        $count_users      = $users->where($where)->count();
        $storeInfo = D('store');
        $storeArray = $storeInfo->where($user_where)->select();
        $count_store = $storeInfo->where($user_where)->count();

        $store_ids=null;
        foreach($storeArray as $key=>$value){
            if($key==0){
                $store_ids=$store_ids.$value['id'];
            }else{
                $store_ids=$store_ids.','.$value['id'];
            }
        }
        $order=M('order');
        $count_where['store_id']=array('in',$store_ids);
        $count_where['order_state']=array('egt','20');
        $count_where['order_type']=array('neq',1);
        $count_where['refund_state']=0;
        $order_lists=$order->where($count_where)->order('order_id desc')->select();
        $count_order=$order->where($count_where)->order('order_id desc')->count();
        $count_price=0;
        foreach ($order_lists as $key=>$value){
            $count_price=$count_price+$value['order_amount'];
        }

        $weichunli_order['store_id']=array('in',$store_ids);
        $weichunli_order['order_state']=array('eq','20');
        $weichunli_order['refund_state']=0;
        $weichunli_count_order=$order->where($weichunli_order)->order('order_id desc')->count();
        $this->assign('weichunli_count_order',$weichunli_count_order);
        $this->assign('user_info',$user_info);
        $this->assign('count_price',$count_price);
        $this->assign('count_store',$count_store);
        $this->assign('count_order',$count_order);
        $this->assign('count_users',$count_users);


        $b_ids=explode(',',$user_info['b_id']);
        if($user_info['level']==1){
            $daiyanwhere='yt_area_angel.province_id='.$b_ids[0].' and yt_area_angel.status>'.$user_info['level'];
        }
        if($user_info['level']==2){
            $daiyanwhere='yt_area_angel.city_id='.$b_ids[1].' and yt_area_angel.status>'.$user_info['level'];
        }
        if($user_info['level']==3){
            $daiyanwhere='yt_area_angel.district_id='.$b_ids[2].' and yt_area_angel.status>'.$user_info['level'];

        }
        $daiyan_count=M('area_angel')
            ->field('yt_users.phone,yt_area_angel.*')
            ->join('yt_users on yt_users.id=yt_area_angel.uid','left')
            ->where($daiyanwhere)->count();
        $this->assign('daiyan_count',$daiyan_count);
        $this->display();
    }
    public function login_out(){
        session('id',null);
        session('u_id',null);
        session('user_id',null);
        session('name',null);
        session('level',null);
        session('b_id',null);
        echo "<script language='javascript' type='text/javascript'>";
        echo "window.location.href='/'";
        echo "</script>";
    }


}